// https://pinia.web3doc.top/introduction.html

import { defineStore } from 'pinia'
import { ref ,computed, reactive } from 'vue'
import api from '@/api'

export const useUserStore = defineStore('user', () => {
	const userInfo = ref({})
	const mobile = ref('')
	const num = ref(0)
	const monthExpiredNum = ref(0)
	const setUser = userinfo => {		//actions
		userInfo.value = userinfo
		mobile.value = userinfo.mobile
	}
	const updateNum = async () => {		//actions
    const account = await api.myAccount()
		num.value = account.account_num
		monthExpiredNum.value = account.monthExpiredNum
	}
	return { 
		userInfo, mobile, setUser,
	  num, monthExpiredNum, updateNum
	}
})

export const useBaseStore = defineStore('base', () => {
	const baseInfo = ref({})
	const setBase = baseinfo => {		//actions
		baseInfo.value = baseinfo
	}
	const updateBase = async () => {		//actions
    const base = await api.getBaseInfo()
		setBase(base)
	}
	return { baseInfo, setBase, updateBase }
})
